import React, { useEffect, useState } from 'react';
import { Modal, Form, Space } from 'antd';
import FormCondition from '@/components/FormCondition';
import { connect } from 'umi';
import TableDataBlock from '@/components/TableDataBlock';
import { ExclamationCircleOutlined } from '@ant-design/icons'
import { notification } from 'antd';
const SettingStandards = (props) => {
    const { visible = false, onClose, loading, onChange, dispatch, reload } = props;
    const { show, detail = {} } = visible;
    const { stage } = detail;
    const [form] = Form.useForm();
    const [stageList, setStageList] = useState([])
    // 确认提交
    const { id } = detail
    useEffect(() => {
        if (show) {
            fetchUserStage()
        }
        else {
            setStageList([])
        }
    }, [show])
    console.log(detail)
    const fetchUserStage = () => {
        dispatch({
            type: 'user/fetchUserStageForChoose',
            payload: {
                organizationUserId: id,
                queryFor: 'manualAdminFinish'
            },
            callback: (e) => {
                const { stageInfoList = [] } = e
                setStageList(stageInfoList)
            }
        })
    }
    const formItems = [

        {
            label: `阶段`,
            name: 'userStageId',
            type: 'stage',
            fieldNames: {
                label: "stageName",
                value: 'userStageId',
                options: 'subStageInfoList'
            },

            select: stageList.map(val => {
                const {
                    stageInfo = {},
                    subStageInfoList = []
                } = val
                const { chooseFlag } = stageInfo
                if (subStageInfoList.length > 0) {
                    return {
                        ...stageInfo,
                        ...val,
                        subStageInfoList: subStageInfoList.map(o => {
                            return {
                                ...o,
                                disabled: o.chooseFlag === '1' ? false : true
                            }
                        })
                    }
                }
                return {
                    ...stageInfo,
                    disabled: chooseFlag === '1' ? true : false
                }
            })
        },
    ];

    const modalProps = {
        title: '手动达标',
        width: 900,
        visible: show,
        maskClosable: true,
        destroyOnClose: true,
        zIndex: 1001,
        confirmLoading: loading,
    };
    const handleUpAudit = () => {
        form.validateFields().then(async (values) => {
            dispatch({
                type: 'user/fetchManualAdminFinish',
                payload: values,
                callback: (e) => {
                    onClose()
                    reload()
                }
            })
        });
    };
    return (
        <Modal {...modalProps} onCancel={onClose} onOk={handleUpAudit}>
            <Space direction={'vertical'} style={{ display: 'flex', textAlign: 'center', justifyContent: 'center', width: '100%' }}>
                <FormCondition form={form} formItems={formItems}></FormCondition>
            </Space>

        </Modal >
    );
};

export default connect(({ order, loading }) => ({
    loading: loading.effects['user/fetchManualAdminFinish'],
}))(SettingStandards);
